<?php
use think\facade\Db;
Db::name('mg_menu')
    ->whereOr("mg_module='{$mg_module}' and name = '问卷管理'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Survey/index'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Survey/add'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Survey/edit'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Survey/del'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Survey/del_option'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Survey/down_temp'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Survey/record'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Survey/import'")
    ->delete();

$parent_id = Db::name('mg_menu')->insertGetId([
    'mg_module'     => $mg_module,
    'name'          => '问卷管理',
    'module'        => $mg_module,
    'router'        => "",
    'controller'    => '',
    'action'        => '',
    'icon'          => 'layui-icon-tabs',
    'status'        => 1,
    'create_time'   => time()
]);

$insert_id_1 = Db::name('mg_menu')->insertGetId([
    'parent_id'     => $parent_id,
    'mg_module'     => $mg_module,
    'name'          => '问卷主题',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/survey_theme",
    'controller'    => 'Survey',
    'action'        => 'survey_theme',
    'icon'          => '',
    'status'        => 1,
    'create_time'   => time()
]);

$insert_id_2 = Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id_1,
    'mg_module'     => $mg_module,
    'name'          => '主题添加',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/survey_theme_add",
    'controller'    => 'Survey',
    'action'        => 'survey_theme_add',
    'icon'          => 'layui-icon-addition',
    'status'        => 1,
    'style'         => 'layui-btn-sm layui-btn-normal',
    'create_time'   => time()
]);

$insert_id_3 = Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id_1,
    'mg_module'     => $mg_module,
    'name'          => '主题编辑',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/survey_theme_edit",
    'controller'    => 'Survey',
    'action'        => 'survey_theme_edit',
    'icon'          => 'layui-icon-edit',
    'status'        => 1,
    'style'         => 'layui-btn-xs layui-btn-normal',
    'create_time'   => time()
]);


$insert_id_4 = Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id_1,
    'mg_module'     => $mg_module,
    'name'          => '主题删除',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/survey_theme_del",
    'controller'    => 'Survey',
    'action'        => 'survey_theme_del',
    'icon'          => 'layui-icon-delete',
    'status'        => 1,
    'style'         => 'layui-btn-xs layui-btn-danger',
    'create_time'   => time()
]);

$insert_id = Db::name('mg_menu')->insertGetId([
    'parent_id'     => $parent_id,
    'mg_module'     => $mg_module,
    'name'          => '题目管理',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/index",
    'controller'    => 'Survey',
    'action'        => 'index',
    'icon'          => '',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '添加题目',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/add",
    'controller'    => 'Survey',
    'action'        => 'add',
    'icon'          => 'layui-icon-addition',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '编辑题目',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/edit",
    'controller'    => 'Survey',
    'action'        => 'edit',
    'icon'          => 'layui-icon-edit',
    'style'         => 'layui-btn-xs layui-btn-normal',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '删除题目',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/del",
    'controller'    => 'Survey',
    'action'        => 'del',
    'icon'          => 'layui-icon-delete',
    'style'         => 'layui-btn-xs layui-btn-danger',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '删除选项',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/del_option",
    'controller'    => 'Survey',
    'action'        => 'del_option',
    'icon'          => 'layui-icon-delete',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '下载模板',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/down_temp",
    'controller'    => 'Survey',
    'action'        => 'down_temp',
    'icon'          => 'layui-icon-download-circle',
    'style'         => 'layui-btn-sm layui-btn-danger',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $parent_id,
    'mg_module'     => $mg_module,
    'name'          => '答题记录',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/record",
    'controller'    => 'Survey',
    'action'        => 'record',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '题库导入',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Survey/import",
    'controller'    => 'Survey',
    'action'        => 'import',
    'status'        => 1,
    'create_time'   => time()
]);